package action;

import java.awt.Toolkit;


public class ActionMove extends Action {

	private int x;
	private int y;
	private int currentX;
	private int currentY;

	public ActionMove(){
		currentX = (int)(Toolkit.getDefaultToolkit().getScreenSize().getWidth()/2);
		currentY = (int)(Toolkit.getDefaultToolkit().getScreenSize().getHeight()/2);
	}


	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}

	public void execute(){
		//		if(Math.abs(x)>10)
		//			currentX = currentX+x*2;
		//		else
		//			currentX+=x;
		//		if(Math.abs(y)>10)
		//			currentY = currentY+y*2;
		//		else
		//			currentY+=y;

		System.out.println("x= "+x+" y= "+y);

		int dx=1,dy=1;
		x=x*96/160;
		y=y*96/160;
		int module = (int) Math.sqrt(x*x+y*y);
		if(module<5)
		{

			if(x<0)
				dx=-1;
			if(y<0)
				dy=-1;
			//			int i=0,j=0; //i sulle x, j sulle y;
			//			while(i<=Math.abs(x) || j<=Math.abs(y)){
			//				if(i<=Math.abs(x)){
			//					currentX+=dx;
			//					i++;
			//				}
			//				if(j<=Math.abs(y)){
			//					currentY+=dy;
			//					j++;
			//				}
			//				try{
			//					robot.mouseMove(currentX,currentY);
			//				}catch(NullPointerException e){
			//					e.printStackTrace();
			//				}
			//			}
			//			try {
			//				Thread.sleep(10);
			//			} catch (InterruptedException e) {
			//				// TODO Auto-generated catch block
			//				e.printStackTrace();
			//			}
			currentX+=x/3;
			currentY+=y/3;
		}
		else if(module >=5 && module <10){
			currentX+=x/2;
			currentY+=y/2;
		}
		else if (module >=10 && module <20)
		{
			currentX+=x;
			currentY+=y;
		}
		else if(module>=20 && module <30){
			currentY+=y*1.5;
			currentX+=x*1.5;
		}
		
		else{
			currentY+=y*2;
			currentX+=x*2;
		}
		try{
			robot.mouseMove(currentX,currentY);
		}catch(NullPointerException e){
			e.printStackTrace();
		}

	}
}
